package com.thor.palmmall.controller.chart;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.thor.commons.exception.ThorServiceException;
import com.thor.commons.util.DateUtil;
import com.thor.commons.util.StringUtil;
import com.thor.palmmall.spi.chart.SChartParam;
import com.thor.palmmall.spi.chart.SChartService;
import com.thor.palmmall.spi.chart.SDateRange;
import com.thor.palmmall.spi.chart.SMaintainCategoryData;
import com.thor.palmmall.spi.chart.SMaintainDetial;
import com.thor.palmmall.spi.chart.SMaintainRepairData;
import com.thor.palmmall.spi.chart.SMaintainReportCondition;
import com.thor.palmmall.spi.chart.SMaintainReportData;
import com.thor.palmmall.spi.chart.SPassengersReport;
import com.thor.palmmall.spi.chart.SPassengersReportParam;
import com.thor.palmmall.spi.chart.SReceiptParam;
import com.thor.palmmall.spi.chart.SReceiptReport;
import com.thor.palmmall.spi.chart.SRental;
import com.thor.palmmall.spi.chart.SRentalParam;
import com.thor.palmmall.spi.chart.SRentalReport;
import com.thor.palmmall.spi.chart.SSalesReport;
import com.thor.palmmall.spi.chart.SSalesType;
import com.thor.palmmall.spi.chart.SSalesTypeParam;
import com.thor.palmmall.spi.common.SResponse;

/**
 * 报表控制器
 * 
 * @author thor
 * 
 */
@Controller
@RequestMapping(value = "/chart")
public class ChartController {

  @Autowired
  private SChartService chartService;

  @RequestMapping(value = "formatdischart.thor")
  public String formatDistChart() {
    return "/chart/formatdischart";
  } // 没数据时默认跳转页面

  @RequestMapping(value = "reportnodata.thor")
  public String formatnodata() {
    return "/chart/nodatadefault";
  }

  @RequestMapping(value = "getformatnodata.thor", method = RequestMethod.GET)
  @ResponseBody
  public String getNoData(String reporttype, String dimensionTypeEquals) {
    String reprotName = null;
    if ("passale".equals(reporttype)) {
      reprotName = "客流销售额统计";
    } else if ("dis".equals(reporttype)) {
      reprotName = "业态经营情况";
    } else if ("rate".equals(reporttype)) {
      reprotName = "收缴率";
    } else if ("flow".equals(reporttype)) {
      if ("flow".equals(dimensionTypeEquals)) {
        reprotName = "楼层销售分布";
      } else {
        reprotName = "业态销售分布";
      }
    } else if ("mstatic".equals(reporttype)) {
      reprotName = "维修统计(单位:件次)";
    } else if ("mrepairer".equals(reporttype)) {
      reprotName = "人员统计(单位:件次)";
    } else if ("mCategory".equals(reporttype)) {
      reprotName = "类别统计(单位:件次)";
    } else if ("mtime".equals(reporttype)) {
      reprotName = "工时统计(单位:小时)";
    } else if ("passenger".equals(reporttype)) {
      reprotName = "客流分布";
    } else if ("rental".equals(reporttype)) {
      reprotName = "出租率";
    } else {
      reprotName = "";
    }
    return reprotName;
  }

  @RequestMapping(value = "passengersaleschart.thor")
  public String passengerSalesChart() {
    return "/chart/passengersaleschart";
  }

  @RequestMapping(value = "getpassengersales.thor", method = RequestMethod.GET)
  @ResponseBody
  public PassengerSalesChart getPassengerSales(String projectid, String passengerflowdate) {
    // 构建xdata
    List<String> xdata = new ArrayList<String>();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
    SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
    Date pfd = null;
    try {
      pfd = sdf1.parse(passengerflowdate);
    } catch (Exception e) {

    }
    Date lastdate = null;
    for (int i = 15; i > 0; i--) {
      lastdate = DateUtil.add(pfd, Calendar.DATE, -i);
      xdata.add(sdf.format(lastdate));
    }
    lastdate = DateUtil.add(pfd, Calendar.DATE, -15); // 从后台查询客流及销售数据
    PassengerSalesChart sc = new PassengerSalesChart();
    SChartParam chartParam = new SChartParam();
    chartParam.setStore(projectid);
    SDateRange dateRange = new SDateRange();
    dateRange.setBeginDate(lastdate);
    dateRange.setEndDate(pfd);
    chartParam.setDateRange(dateRange);
    SResponse<List<SSalesReport>> resp = chartService.getSalesReport(chartParam);
    List<SSalesReport> result = resp.getBody();
    if (result == null || result.size() == 0) {
      return sc;
    }
    sc.setXdata(xdata);
    PSChartSeries pcsp = new PSChartSeries();
    pcsp.setName("客流量(万人次)");
    List<BigDecimal> pcspdata = new ArrayList();
    PSChartSeries pcss = new PSChartSeries();
    pcss.setName("销售额(万)");
    List<BigDecimal> pcssdata = new ArrayList();
    for (String xdate : xdata) {
      for (SSalesReport rs : result) {
        if (sdf.format(rs.getDate()).equals(xdate)) {
          BigDecimal passenger = rs.getPassengers();
          if (passenger == null)
            pcspdata.add(BigDecimal.ZERO);
          else
            pcspdata.add(passenger.divide(new BigDecimal(10000)));
          BigDecimal sale = rs.getSales();
          if (sale == null)
            pcssdata.add(BigDecimal.ZERO);
          else
            pcssdata.add(sale.divide(new BigDecimal(10000)));
        }
      }
    }

    pcsp.setData(pcspdata);
    pcss.setData(pcssdata);
    sc.getSeries().add(pcsp);
    sc.getSeries().add(pcss);

    return sc;

  }

  @RequestMapping(value = "formatflowchart.thor")
  public String formatFlowChart() {
    return "/chart/formatflowchart";
  }

  @RequestMapping(value = "getformatdis.thor", method = RequestMethod.GET)
  @ResponseBody
  public FormatDisChart getFormatDis(String projectid) {
    SRentalParam rentalParam = new SRentalParam();
    rentalParam.setStore(projectid);
    rentalParam.setDate(new Date());
    SResponse<SRentalReport> results = chartService.getRentalReport(rentalParam);
    List<SRental> rentalList = results.getBody().getRentals();
    FormatDisChart chart = new FormatDisChart();

    if (rentalList == null || rentalList.size() == 0) {
      return chart;
    }
    chart = new FormatDisChart();
    BigDecimal sumArea = BigDecimal.ZERO;
    for (SRental srt : rentalList) {
      sumArea = sumArea.add(srt.getArea()).setScale(2, BigDecimal.ROUND_HALF_UP);
    }
    FormatDisChartSeries fdcs = new FormatDisChartSeries();
    fdcs.setName("占比");
    fdcs.setType("pie");
    for (SRental srt : rentalList) {
      FormatDisChartItem ci = new FormatDisChartItem();
      ci.setName(srt.getCategory().getName() + "[" + srt.getArea() + "㎡]");
      ci.setSelected(false);
      ci.setSliced(false);
      ci.setY(srt.getArea().divide(sumArea, 2, BigDecimal.ROUND_HALF_UP));
      fdcs.getData().add(ci);
    }
    fdcs.getData().get(0).setSelected(true);
    fdcs.getData().get(0).setSliced(true);
    chart.getSeries().add(fdcs);
    return chart;
  }

  @RequestMapping(value = "formatrentalchart.thor")
  public String formatRentalChart() {
    return "/chart/formatrentalchart";
  }

  @RequestMapping(value = "getformatrental.thor", method = RequestMethod.GET)
  @ResponseBody
  public FormatDisChart getFormatRental(String projectid) throws ParseException {
    SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
    SRentalParam rentalParam = new SRentalParam();
    rentalParam.setStore(projectid);
    rentalParam.setDate(new Date());
    SResponse<SRentalReport> results = chartService.getRentalReport(rentalParam);
    SRentalReport rentalReport = results.getBody();
    FormatDisChart chart = new FormatDisChart();
    chart = new FormatDisChart();
    FormatDisChartSeries fdcs = new FormatDisChartSeries();
    fdcs.setName("占比");
    fdcs.setType("pie");
    BigDecimal area = rentalReport.getArea();
    BigDecimal rentArea = rentalReport.getRentArea();
    BigDecimal unRentArea = area.subtract(rentArea).setScale(2, BigDecimal.ROUND_HALF_UP);
    // BigDecimal total = receivable.add(receive).add(tardy);
    if (area == null || area.compareTo(BigDecimal.ZERO) == 0 || rentArea == null
        || rentArea.compareTo(BigDecimal.ZERO) == 0 || unRentArea.compareTo(BigDecimal.ZERO) == 0
        || unRentArea == null) {
      return chart;
    }

    chart.setChartRemark(sdf1.format(new Date()) + "出租率<br/> 可出租面积：" + area);

    FormatDisChartItem receivetotal = new FormatDisChartItem();
    receivetotal.setName("出租面积" + "[" + rentArea + "]");//
    receivetotal.setSelected(false);
    receivetotal.setSliced(false);
    receivetotal.setY(
        new BigDecimal(rentArea.divide(area, 2, BigDecimal.ROUND_HALF_UP).doubleValue() * 100));
    fdcs.getData().add(receivetotal);

    FormatDisChartItem tardytotal = new FormatDisChartItem();
    tardytotal.setName("未出租面积" + "[" + unRentArea + "]");//
    tardytotal.setSelected(false);
    tardytotal.setSliced(false);
    tardytotal.setY(
        new BigDecimal(unRentArea.divide(area, 2, BigDecimal.ROUND_HALF_UP).doubleValue() * 100));
    fdcs.getData().add(tardytotal);

    fdcs.getData().get(0).setSelected(true);
    fdcs.getData().get(0).setSliced(true);

    chart.getSeries().add(fdcs);

    return chart;
  }

  @RequestMapping(value = "formatratechart.thor")
  public String formatRateChart() {
    return "/chart/formatratechart";
  }

  @RequestMapping(value = "getformatrate.thor", method = RequestMethod.GET)
  @ResponseBody
  public FormatDisChart getFormatRate(String projectid, String ratedate) throws ParseException {
    SReceiptParam receiptParam = new SReceiptParam();
    receiptParam.setSettle(ratedate);
    receiptParam.setStore(projectid);
    SResponse<SReceiptReport> results = chartService.getReceiptReport(receiptParam);
    SReceiptReport receiptReport = results.getBody();
    FormatDisChart chart = new FormatDisChart();
    chart = new FormatDisChart();
    FormatDisChartSeries fdcs = new FormatDisChartSeries();
    fdcs.setName("占比");
    fdcs.setType("pie");
    BigDecimal receivable = receiptReport.getReceivable();
    BigDecimal receive = receiptReport.getReceived();
    BigDecimal tardy = receiptReport.getDebt();
    // BigDecimal total = receivable.add(receive).add(tardy);
    if (receivable == null || receivable.compareTo(BigDecimal.ZERO) == 0) {
      return chart;
    }

    chart.setChartRemark(ratedate + "收缴率<br/> 应收合计：" + receivable);

    FormatDisChartItem receivetotal = new FormatDisChartItem();
    receivetotal.setName("实收" + "[" + receive + "]");//
    receivetotal.setSelected(false);
    receivetotal.setSliced(false);
    receivetotal.setY(new BigDecimal(
        receive.divide(receivable, 2, BigDecimal.ROUND_HALF_UP).doubleValue() * 100));
    fdcs.getData().add(receivetotal);

    FormatDisChartItem tardytotal = new FormatDisChartItem();
    tardytotal.setName("欠收" + "[" + tardy + "]");//
    tardytotal.setSelected(false);
    tardytotal.setSliced(false);
    tardytotal.setY(
        new BigDecimal(tardy.divide(receivable, 2, BigDecimal.ROUND_HALF_UP).doubleValue() * 100));
    fdcs.getData().add(tardytotal);

    fdcs.getData().get(0).setSelected(true);
    fdcs.getData().get(0).setSliced(true);

    chart.getSeries().add(fdcs);

    return chart;
  }

  @RequestMapping(value = "formatpaschart.thor")
  public String formatPasChart() {
    return "/chart/formatpaschart";
  }

  @RequestMapping(value = "getformatpas.thor", method = RequestMethod.GET)
  @ResponseBody
  public FormatDisChart getFormatPassenger(String projectEquals, String passengerFlowDateEquals)
      throws ThorServiceException, ParseException {

    SPassengersReportParam pasParam = new SPassengersReportParam();
    pasParam.setStore(projectEquals);
    pasParam.setDate(new SimpleDateFormat("yyyy-MM-dd").parse(passengerFlowDateEquals));
    SResponse<List<SPassengersReport>> resp = chartService.getPassengersReport(pasParam);// 获取客流返回数据
    List<SPassengersReport> passengers = resp.getBody();
    FormatDisChart chart = new FormatDisChart();
    if (passengers == null || passengers.size() == 0) {
      return chart;
    }
    chart = new FormatDisChart();
    chart.setChartRemark(passengerFlowDateEquals + "客流分布");
    FormatDisChartSeries fdcs = new FormatDisChartSeries();
    BigDecimal totalpassengers = getTotalPassenger(passengers);
    fdcs.setName("客流分布");
    fdcs.setType("pie");
    for (SPassengersReport passenger : passengers) {
      FormatDisChartItem ci = new FormatDisChartItem();
      ci.setName(passenger.getEntrance() + "[" + passenger.getInVolume() + "]");
      ci.setSelected(false);
      ci.setSliced(false);
      Double value = passenger.getInVolume().divide(totalpassengers, 2, BigDecimal.ROUND_HALF_UP)
          .doubleValue() * 100;
      ci.setY(new BigDecimal(value * 100));
      fdcs.getData().add(ci);
    }
    fdcs.getData().get(0).setSelected(true);
    fdcs.getData().get(0).setSliced(true);
    chart.getSeries().add(fdcs);

    return chart;
  }

  @RequestMapping(value = "formatflowChart.thor")
  public String formatflowChart() {
    return "/chart/formatflowchart";
  }

  @RequestMapping(value = "getformatflow.thor", method = RequestMethod.GET)
  @ResponseBody
  public FormatDisChart getFormatFlow(String projectEquals, String salesDateEquals,
      String dimensionTypeEquals) throws ThorServiceException, ParseException {
    SSalesTypeParam salesTypeParam = new SSalesTypeParam();
    salesTypeParam.setStore(projectEquals);
    salesTypeParam.setDate(new SimpleDateFormat("yyyy-MM-dd").parse(salesDateEquals));
    if (dimensionTypeEquals != null && "floor".equals(dimensionTypeEquals)) {
      dimensionTypeEquals = "floor";
    } else if ("bizType".equals(dimensionTypeEquals)) {
      dimensionTypeEquals = "bizType";
    } else {
      dimensionTypeEquals = null;
    }
    salesTypeParam.setType(dimensionTypeEquals);
    SResponse<List<SSalesType>> resp = chartService.getSalesReportType(salesTypeParam);// 获取销售返回数据
    List<SSalesType> sales = resp.getBody();
    FormatDisChart chart = new FormatDisChart();
    if (sales == null || sales.size() == 0) {
      if (ObjectUtils.equals("bizType", salesTypeParam.getType())
          || StringUtil.isNullOrBlank(salesTypeParam.getType())) {
        chart.setFlag("sale");
      } else {
        chart.setFlag("flow");
      }
      return chart;
    }
    FormatDisChartSeries fdcs = new FormatDisChartSeries();
    BigDecimal totalAmount = getTotalAmount(sales);
    // 业态
    if (ObjectUtils.equals("bizType", salesTypeParam.getType())
        || StringUtil.isNullOrBlank(salesTypeParam.getType())) {
      fdcs.setName("业态占比");
      chart.setChartRemark(salesDateEquals + "业态销售分布");
    }
    // 楼层
    if (ObjectUtils.equals("floor", salesTypeParam.getType())
        || StringUtil.isNullOrBlank(salesTypeParam.getType())) {
      fdcs.setName("楼层占比");
      chart.setChartRemark(salesDateEquals + "楼层销售分布");
    }
    fdcs.setType("pie");
    for (SSalesType sale : sales) {
      FormatDisChartItem ci = new FormatDisChartItem();
      ci.setName(sale.getUcn().getName() + "[" + sale.getSales() + "]");
      ci.setSelected(false);
      ci.setSliced(false);
      Double value = sale.getSales().divide(totalAmount, 2, BigDecimal.ROUND_HALF_UP).doubleValue();
      ci.setY(new BigDecimal(value * 100));
      fdcs.getData().add(ci);
    }
    fdcs.getData().get(0).setSelected(true);
    fdcs.getData().get(0).setSliced(true);
    chart.getSeries().add(fdcs);

    return chart;
  }

  @RequestMapping(value = "formatmtstaticchart.thor")
  public String formatmtstaticchart() {
    return "/chart/formatmtstaticchart";
  }

  @RequestMapping(value = "getformatmainstatic.thor", method = RequestMethod.GET)
  @ResponseBody
  public FormatDisChart getformatmainstatic(String projectid, String beginDate, String endDate)
      throws ParseException {
    SMaintainReportCondition condition = new SMaintainReportCondition();
    condition.setStore(projectid);
    SDateRange daterange = new SDateRange();
    daterange.setBeginDate(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(beginDate));
    daterange.setEndDate(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(endDate));
    condition.setDateRange(daterange);
    SResponse<SMaintainReportData> results = chartService.getMaintainReport(condition);
    List<SMaintainDetial> dtl = results.getBody().getDetails();
    FormatDisChart chart = new FormatDisChart();

    if (dtl == null || dtl.size() == 0) {
      return chart;
    }
    chart = new FormatDisChart();
    BigDecimal sumQty = results.getBody().getQty();
    FormatDisChartSeries fdcs = new FormatDisChartSeries();
    fdcs.setName("占比");
    fdcs.setType("pie");
    for (SMaintainDetial srt : dtl) {
      FormatDisChartItem ci = new FormatDisChartItem();
      if ("ineffect".equals(srt.getBizState())) {
        ci.setName("已提交[" + srt.getQty() + "件数]");
      } else if ("repairing".equals(srt.getBizState())) {
        ci.setName("维修中[" + srt.getQty() + "件数]");
      } else if ("distracted".equals(srt.getBizState())) {
        ci.setName("转移[" + srt.getQty() + "件数]");
      } else if ("finished".equals(srt.getBizState())) {
        ci.setName("已完成[" + srt.getQty() + "件数]");
      } else if ("overTime".equals(srt.getBizState())) {
        ci.setName("已超时[" + srt.getQty() + "件数]");
      }
      ci.setSelected(false);
      ci.setSliced(false);
      ci.setY(srt.getQty().divide(sumQty, 2, BigDecimal.ROUND_HALF_UP));
      fdcs.getData().add(ci);
    }
    fdcs.getData().get(0).setSelected(true);
    fdcs.getData().get(0).setSliced(true);
    chart.getSeries().add(fdcs);
    return chart;
  }

  @RequestMapping(value = "formatmtrepairerchart.thor")
  public String formatrepairerchart() {
    return "/chart/formatmtrepairerchart";
  }

  @RequestMapping(value = "getformatmainrepair.thor", method = RequestMethod.GET)
  @ResponseBody
  public FormatDisChart getformatmainrepair(String projectid, String beginDate, String endDate)
      throws ParseException {
    SMaintainReportCondition condition = new SMaintainReportCondition();
    condition.setStore(projectid);
    SDateRange daterange = new SDateRange();
    daterange.setBeginDate(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(beginDate));
    daterange.setEndDate(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(endDate));
    condition.setDateRange(daterange);
    SResponse<List<SMaintainRepairData>> results = chartService.getRepairReport(condition);
    FormatDisChart chart = new FormatDisChart();

    if (results.getBody() == null || results.getBody().size() == 0) {
      return chart;
    }
    chart = new FormatDisChart();
    BigDecimal sumQty = getAllQty(results.getBody());
    FormatDisChartSeries fdcs = new FormatDisChartSeries();
    fdcs.setName("占比");
    fdcs.setType("pie");
    for (SMaintainRepairData srt : results.getBody()) {
      FormatDisChartItem ci = new FormatDisChartItem();
      ci.setName(srt.getRepairPerson().getName() + " [" + srt.getQty() + "件数]");
      ci.setSelected(false);
      ci.setSliced(false);
      ci.setY(srt.getQty().divide(sumQty, 2, BigDecimal.ROUND_HALF_UP));
      fdcs.getData().add(ci);
    }
    fdcs.getData().get(0).setSelected(true);
    fdcs.getData().get(0).setSliced(true);
    chart.getSeries().add(fdcs);
    return chart;
  }

  @RequestMapping(value = "formatmttimechart.thor")
  public String formatmttimechart() {
    return "/chart/formatmttimechart";
  }

  @RequestMapping(value = "getformatmaintime.thor", method = RequestMethod.GET)
  @ResponseBody
  public FormatDisChart getformatmaintime(String projectid, String beginDate, String endDate)
      throws ParseException {
    SMaintainReportCondition condition = new SMaintainReportCondition();
    condition.setStore(projectid);
    SDateRange daterange = new SDateRange();
    daterange.setBeginDate(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(beginDate));
    daterange.setEndDate(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(endDate));
    condition.setDateRange(daterange);
    SResponse<List<SMaintainRepairData>> results = chartService.getRepairReport(condition);
    FormatDisChart chart = new FormatDisChart();

    if (results.getBody() == null || results.getBody().size() == 0) {
      return chart;
    }
    chart = new FormatDisChart();
    BigDecimal sumHour = getAllHour(results.getBody());
    if (sumHour.compareTo(BigDecimal.ZERO) == 0) {
      return chart;
    }
    FormatDisChartSeries fdcs = new FormatDisChartSeries();
    fdcs.setName("占比");
    fdcs.setType("pie");
    for (SMaintainRepairData srt : results.getBody()) {
      FormatDisChartItem ci = new FormatDisChartItem();
      ci.setName(srt.getRepairPerson().getName() + " [" + srt.getRepairTime() + "小时]");
      ci.setSelected(false);
      ci.setSliced(false);
      if (srt.getRepairTime().compareTo(BigDecimal.ZERO) == 0) {
        continue;
      }
      ci.setY(srt.getRepairTime().divide(sumHour, 2, BigDecimal.ROUND_HALF_UP));
      fdcs.getData().add(ci);
    }
    fdcs.getData().get(0).setSelected(true);
    fdcs.getData().get(0).setSliced(true);
    chart.getSeries().add(fdcs);
    return chart;
  }

  @RequestMapping(value = "formatmtCategorychart.thor")
  public String formatmtCategorychart() {
    return "/chart/formatmtCategorychart";
  }

  @RequestMapping(value = "getformatmaincategory.thor", method = RequestMethod.GET)
  @ResponseBody
  public FormatDisChart getformatmaincategory(String projectid, String beginDate, String endDate)
      throws ParseException {
    SMaintainReportCondition condition = new SMaintainReportCondition();
    condition.setStore(projectid);
    SDateRange daterange = new SDateRange();
    daterange.setBeginDate(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(beginDate));
    daterange.setEndDate(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(endDate));
    condition.setDateRange(daterange);
    SResponse<List<SMaintainCategoryData>> results = chartService.getCategoryReport(condition);
    FormatDisChart chart = new FormatDisChart();

    if (results.getBody() == null || results.getBody().size() == 0) {
      return chart;
    }
    chart = new FormatDisChart();
    BigDecimal sumQty = getAllCategoryQty(results.getBody());
    if (sumQty.compareTo(BigDecimal.ZERO) == 0) {
      return chart;
    }
    FormatDisChartSeries fdcs = new FormatDisChartSeries();
    fdcs.setName("占比");
    fdcs.setType("pie");
    for (SMaintainCategoryData srt : results.getBody()) {
      FormatDisChartItem ci = new FormatDisChartItem();
      ci.setName(srt.getMaitainType() + " [" + srt.getQty() + "件数]");
      ci.setSelected(false);
      ci.setSliced(false);
      if (srt.getQty().compareTo(BigDecimal.ZERO) == 0) {
        continue;
      }
      ci.setY(srt.getQty().divide(sumQty, 2, BigDecimal.ROUND_HALF_UP));
      fdcs.getData().add(ci);
    }
    fdcs.getData().get(0).setSelected(true);
    fdcs.getData().get(0).setSliced(true);
    chart.getSeries().add(fdcs);
    return chart;
  }

  /**
   * @param body
   * @return
   */
  private BigDecimal getAllCategoryQty(List<SMaintainCategoryData> body) {
    BigDecimal sumQty = new BigDecimal(0);
    for (SMaintainCategoryData data : body) {
      sumQty = sumQty.add(data.getQty());
    }
    return sumQty;
  }

  /**
   * @param body
   * @return
   */
  private BigDecimal getAllHour(List<SMaintainRepairData> body) {
    BigDecimal sumHour = new BigDecimal(0);
    for (SMaintainRepairData data : body) {
      sumHour = sumHour.add(data.getRepairTime());
    }
    return sumHour;
  }

  /**
   * @param body
   * @return
   */
  private BigDecimal getAllQty(List<SMaintainRepairData> body) {
    BigDecimal sumQty = new BigDecimal(0);
    for (SMaintainRepairData data : body) {
      sumQty = sumQty.add(data.getQty());
    }
    return sumQty;
  }

  private BigDecimal getTotalAmount(List<SSalesType> sales) {
    BigDecimal totalAmount = new BigDecimal(0);
    for (SSalesType salestype : sales) {
      totalAmount = totalAmount.add(salestype.getSales());
    }
    return totalAmount;
  }

  private BigDecimal getTotalPassenger(List<SPassengersReport> passengers) {
    BigDecimal totalAmount = new BigDecimal(0);
    for (SPassengersReport passenger : passengers) {
      totalAmount = totalAmount.add(passenger.getInVolume());
    }
    return totalAmount;
  }

  private String pasrseDate(String ratedate) {
    return ratedate.substring(0, 7).replace("-", "");
  }

}
